<!-- Author:Rain -->
<template>
    <h1 style="transform: scale(2);">
        账号:<input  v-model="form.username" type="text"><br>
        密码:<input type="password" v-model="form.password"><br>
        <button @click="doLogin">进行登录！！！</button>
    </h1>
</template> 

<script setup lang="js">
let Module = import.meta.glob("@/views/**/*.vue");
// import router from "@/router/index"
// console.log(Module);
import axios from 'axios';
import {useRoutesStore} from "@/stores/counter"
import { reactive ,toRaw} from "vue"
const store=useRoutesStore()
import { useRouter } from "vue-router"
const router=useRouter()
const form=reactive({
    username:"admin",
    password:"12345"
})
function doLogin(){
    let formData=new FormData()
    formData.append("username",form.username)
    formData.append("password",form.password)
    //为什么这里会是options方法
    axios.post("http://localhost:8080/login",formData,{
       
    }).then(async val=>{//前端这边传过来的是JSON数据
        let {data}=val
        console.log(val);
        //这里在进行一个判断
        // if(data.id){//这里已经有了一个用户了
        //     let res=await axios.get("http://localhost:8080/routes?id="+data.id)
        //     let {data:{data:routes}}=res
        //     routes.forEach((item)=>{
        //         store.AddRoute(item)
        //         // router.addRoute({
        //         //     ...item,
        //         //     component:Module[`/src/views/${item.component}.vue`]
        //         // })
        //     })
        // }
        // //目前已经在store中进行了存储操作！！！
        // // console.log(store.routes);
        // console.log(router.getRoutes());
        // router.push("/home")
    }).catch(err=>{
        console.log(err);
    })
}

</script>

<style scoped>

</style>